# coding=utf-8
# -*- coding: utf-8 -*-
from common.driver_tools import DriverTools
'''
封装appium常用的方法
'''


class BaseOperation():

    typeapp = 'web'
    if typeapp == 'web':
        driver = DriverTools.get_webdriver()
    elif typeapp == 'app':
        driver = DriverTools.get_appdriver()
    else:
        print("type参数异常！")

    @classmethod
    def update_type(cls, new_type):
        cls.typeapp = new_type
    # 允许子类修改父类type值
    # @classmethod
    # def updatetype(cls, new_type):
    #     cls.type = new_type

    # 进入app应用
    def activePack(self, PackageName):
        return self.driver.activate_app(PackageName)

    # 访问web-URL
    def visit(self, url):
        self.driver.get(url)
        self.driver.maximize_window()

    # 获取元素
    def get_element(self, loc):
        return self.driver.find_element(*loc)

    # 清空
    def clear(self, loc):
        return self.get_element(loc).clear()

    # 输入
    def input_txt(self, loc, txt):
        return self.get_element(loc).send_keys(txt)

    # 点击
    def click(self, loc):
        return self.get_element(loc).click()

    # 按键输入
    def press(self, num):
        return self.driver.press_keycode(num)

    # 切换native/webview
    def switchType(self, typeName):
        return self.driver.switch_to.context(typeName)
